<template>
  <div class="analysis-table">
    <!-- <div class="name">
      <span>交叉(卡方)</span>
      <span>
        <el-select v-model="chiSquareValue" style="width: 200px">
          <el-option label="数字(占比)" value="1" />
          <el-option label="数字" value="2" />
          <el-option label="百分比" value="3" />
        </el-select>
      </span>
    </div> -->
    <div class="chart-item" v-if="noneReference">
      <table style="width: 100%" v-if="currentData" id="score">
        <thead>
          <tr>
            <th :colspan="10">正态性检验分析结果</th>
          </tr>
          <tr>
            <th rowspan="2" colspan="1">名称</th>
            <th rowspan="2" colspan="1">样本量</th>
            <th rowspan="2" colspan="1">平均值</th>
            <th rowspan="2" colspan="1">标准差</th>
            <th rowspan="2" colspan="1">偏度</th>
            <th rowspan="2" colspan="1">峰度</th>
            <th rowspan="1" colspan="2">Kolmogorov-Smirnov检验</th>
            <th rowspan="1" colspan="2">Shapiro-Wilk检验</th>
          </tr>
          <tr>
            <th>统计量D 值</th>
            <th>p</th>
            <th>统计量W 值</th>
            <th>p</th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="(item, index) in currentData.items[0].groupData" :key="index">
            <td>{{ item.name }}</td>
            <td>{{ item.count }}</td>
            <td>{{ item.mean.toFixed(3) }}</td>
            <td>{{ item.std.toFixed(3) }}</td>
            <td>{{ item.skewness.toFixed(3) }}</td>
            <td>{{ item.kurtosis.toFixed(3) }}</td>
            <td>{{ item.ks_statistic.toFixed(3) }}</td>
            <td>{{ item.ks_pvalue.toFixed(3) }}</td>
            <td>{{ item.sw_statistic.toFixed(3) }}</td>
            <td>{{ item.sw_pvalue.toFixed(3) }}</td>
          </tr>
        </tbody>
      </table>
    </div>
    <template v-if="!noneReference">
      <div class="chart-item" v-for="(i, j) in currentData.items" :key="j">
        <table style="width: 100%" v-if="currentData" id="score">
          <thead>
            <tr>
              <th :colspan="12">{{ i.title }}</th>
            </tr>
            <tr>
              <th rowspan="2" colspan="1">名称</th>
              <th rowspan="2" colspan="1">样本量</th>
              <th rowspan="2" colspan="1">平均值</th>
              <th rowspan="2" colspan="1">标准差</th>
              <th rowspan="2" colspan="1">偏度</th>
              <th rowspan="2" colspan="1">峰度</th>
              <th rowspan="1" colspan="2">Kolmogorov-Smirnov检验</th>
              <th rowspan="1" colspan="2">Shapiro-Wilk检验</th>
              <th rowspan="1" colspan="2">Jarque-Bera检验</th>
            </tr>
            <tr>
              <th>统计量D 值</th>
              <th>p</th>
              <th>统计量W 值</th>
              <th>p</th>
              <th>χ2</th>
              <th>p 值</th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="(item, index) in i.groupData" :key="index">
              <td>{{ item.name }}</td>
              <td>{{ item.count }}</td>
              <td>{{ item.mean.toFixed(3) }}</td>
              <td>{{ item.std.toFixed(3) }}</td>
              <td>{{ item.skewness.toFixed(3) }}</td>
              <td>{{ item.kurtosis?.toFixed(3) || null }}</td>
              <td>{{ item.ks_statistic.toFixed(3) }}</td>
              <td>{{ item.ks_pvalue.toFixed(3) }}</td>
              <td>{{ item.sw_statistic.toFixed(3) }}</td>
              <td>{{ item.sw_pvalue.toFixed(3) }}</td>
              <td>{{ item.jb_statistic.toFixed(3) }}</td>
              <td>{{ item.jb_pvalue.toFixed(3) }}</td>
            </tr>
          </tbody>
        </table>
      </div>
    </template>

    <div id="describe" v-if="currentData.analyse1">
      <div v-if="currentData.analyse1">
        <div class="title">分析建议</div>
        <div v-html="currentData.analyse1"></div>
      </div>
    </div>
    <div class="chart-item" v-if="noneReference">
      <table style="width: 100%" v-if="currentData" id="score">
        <thead>
          <tr>
            <th :colspan="5">Jarque-Bera检验</th>
          </tr>
          <tr>
            <th rowspan="1" colspan="1">名称</th>
            <th rowspan="1" colspan="1">样本量</th>
            <th rowspan="1" colspan="1">χ2</th>
            <th rowspan="1" colspan="1">df</th>
            <th rowspan="1" colspan="1">p值</th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="(item, index) in currentData.items[0].groupData" :key="index">
            <td>{{ item.name }}</td>
            <td>{{ item.count }}</td>
            <td>{{ item.jb_statistic.toFixed(3) }}</td>
            <td>{{}}</td>
            <td>{{ item.jb_pvalue.toFixed(3) }}</td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
</template>

<script setup>
import { onMounted } from 'vue-demi'
import LineChart from '../LineChart.vue'
import { chartOption } from '../chart'
const chiSquareValue = ref('1')
const tableData = ref([])
const selectValue = ref('1')
const noneReference = ref(true)
const prop = defineProps({
  data: {
    type: Object,
    default: () => ({})
  },
  method: {
    type: Object,
    default: () => ({})
  }
})
const currentData = ref('')
onMounted(() => {
  console.log(prop.data)
  console.log(prop.method)
  if (prop.method?.param?.x != '') {
    // 有参考值
    noneReference.value = false
  } else {
    // 无参考值
    noneReference.value = true
  }
  setData()
})
const setData = () => {
  const data = JSON.parse(JSON.stringify(prop.data))
  currentData.value = data
}
const getMinNum = (arr) => {
  if (arr.length == 0) {
    return ''
  }
  const min = Math.min.apply(null, arr)
  const max = Math.max.apply(null, arr)
  if (max / min > 1000) {
    return ''
  } else {
    if (Math.abs(min) < 1) {
      return Math.floor(min * 10) / 10
    } else {
      return Math.floor(min)
    }
  }
}
</script>

<style lang="scss" scoped>
.name {
  padding: 20px;
  text-align: center;
  font-size: 20px;
  font-weight: 700;
}
.entropyChange {
  margin-left: 10px;
  border: 1px solid #000;
  cursor: pointer;
}
.chart-item {
  // border-bottom: 1px solid #ccc;
  padding-bottom: 10px;
  margin: 20px 0 40px 0;
  box-shadow: 0 0 10px #ccc;
  padding: 10px;
  border-radius: 5px;
}
.chart {
  width: 100%;
  height: 400px;
}
.title {
  display: flex;
  justify-content: space-between;
  position: relative;
  padding: 20px;
  font-weight: 700;
  font-size: 20px;
  line-height: 30px;
  .tools {
    display: flex;
  }
  &::after {
    position: absolute;
    content: '';
    left: 0;
    top: 25px;
    height: 20px;
    width: 5px;
    background-color: #178aec;
  }
}
#describe {
  margin: 20px 0 40px 0;
  box-shadow: 0 0 10px #ccc;
  padding: 10px;
  border-radius: 5px;
  padding-bottom: 20px;
}
</style>
<style lang="scss">
.analysis-table {
  table {
    /* width: 100%; */
    /* border: 1px solid #DDDDDD; */
    /* width: 1137px; */
    border-collapse: collapse;
    font-size: 14px;
    background-color: #fff;
    margin-bottom: 10px;
  }

  table tr {
    width: 100%;
    /* line-height: 35px; */
    height: 27px;
    /* height: 35px; */
    text-align: center;
  }

  table tr th {
    /* background: #fafafa; */
    color: #000;
    font-weight: 400;
    /* border: 1px solid #DDDDDD; */
    line-height: 30px;
    text-align: center;
    border-bottom: 1px solid;
  }

  table tr td {
    color: #000;
    /* border: 1px solid #DDDDDD; */
    /* border-bottom: 2px solid; */
  }
}
</style>
